package com.itheima.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.constant.MessageConst;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.entity.Result;
import com.itheima.pojo.CheckGroup;
import com.itheima.pojo.CheckItem;
import com.itheima.pojo.Menu;
import com.itheima.service.MenuService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author: xinliang
 * @date: Created in 2020/3/7
 * @description:
 * @version: 1.0
 */
@RestController
@RequestMapping("/menu")
@Slf4j
public class MenuController {
    @Reference
    MenuService menuService;

    //新增
    @RequestMapping("/add")
    public Result add(@RequestBody Menu menu){
        log.debug("MenuController:add : checkGroup:" +menuService);
        menuService.add(menu);
        log.debug("菜单项添加成功");
        //新增成功
        return new Result(true, MessageConst.ADD_MENU_SUCCESS);
    }


    @RequestMapping("/findPage")
    public Result findByPage(@RequestBody QueryPageBean queryPageBean){
        log.debug("CheckGroupController{"+queryPageBean+"}");
        PageResult pageResult = menuService.findByPage(queryPageBean);
        log.debug("菜单分页查询成功!!");
        return new Result(true, MessageConst.QUERY_MENU_SUCCESS, pageResult);
    }


    @RequestMapping("/delById")
    public Result delById(Integer id){
        log.debug("MenuController:delete: " + id);
        menuService.delById(id);
        log.debug("菜单项删除成功!!");
        return new Result(true, MessageConst.DELETE_MENU_SUCCESS);
    }


    @RequestMapping("/findById")
    public Result findById(Integer id){
        log.debug("MenuController:findById: " + id);
        Menu menu = menuService.findById(id);
        log.debug("菜单项查询成功!!");
        return new Result(true, MessageConst.QUERY_MENU_SUCCESS,menu);
    }



    @RequestMapping("/edit")
    public Result edit(@RequestBody Menu menu){
        log.debug("MenuController:edit: " + menu);
        menuService.edit(menu);
        log.debug("菜单项修改成功!!");
        return new Result(true, MessageConst.EDIT_MENU_SUCCESS);

}}
